﻿namespace Digitalmes.Core.Common.PublishStrategies;

/// <summary>
/// 发布通知并发执行，不会等待执行结果。注意，使用此方式不能捕获任何异常。
/// </summary>
public sealed class ParallelNoWaitPublisher : INotificationPublisher
{
    public Task Publish(IEnumerable<NotificationHandlerExecutor> handlerExecutors, INotification notification, CancellationToken cancellationToken)
    {
        foreach (var handler in handlerExecutors)
        {
            _ = Task.Run(() => handler.HandlerCallback(notification, cancellationToken));
        }

        return Task.CompletedTask;
    }
}
